<template>
    <div>
        <div class="menuadd">
            <el-button round type="primary" plain @click="addmenu">添加</el-button>
        </div>

        <el-table :data="specslist" style="width: 100%;margin-bottom: 20px;" row-key="id"
            :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">

            <el-table-column prop="id" label="序号" width="180">
            </el-table-column>

            <el-table-column prop="specsname" label="规格名称" width="180"></el-table-column>

            <el-table-column prop="attrs" label="规格可选值">
                <template v-slot="$prop">
                    <el-button v-for="item in $prop.row.attrs" :key="item" round type="primary" size="mini" plain>{{
                            item
                    }}</el-button>
                </template>
            </el-table-column>


            <el-table-column prop="status" label="规格状态">
                <template v-slot="$prop">

                    <el-button v-if="$prop.row.status == 1" round type="primary" size="mini" plain>正常</el-button>
                    <el-button v-else round type="warning" size="mini" plain>禁用</el-button>
                </template>
            </el-table-column>


            <el-table-column label="操作">
                <template v-slot="$prop">
                    <el-button round type="primary" size="mini" @click="change($prop.row.id)" plain>编辑</el-button>
                    <el-button round type="danger" size="mini" @click="del($prop.row.id)" plain>删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination background layout="prev, pager, next" :page-size="size" :total="specstotal"
            @current-change="changepage"></el-pagination>

        <v-dialog :info="info" ref="son" />
    </div>
</template>


<script>
// import { del } from "vue";
import { mapActions, mapState } from "vuex"
import vDialog from "./dialog.vue"


export default {
    computed: {
        ...mapState("specs", ["specslist", "specstotal"])
    },
    mounted() {
        this.getspecslist({ page: this.page, size: this.size })
        this.getspecstotal()
    },
    methods: {
        ...mapActions("specs", ["getspecslist", "getspecstotal"]),
        // 新增
        addmenu() {
            this.info.isShow = true
        },
        // 编辑
        change(useradd) {
            // console.log(useradd ,1223);
            console.log(this.$refs.son);
            this.info.isShow = true
        },
        // 删除
        del(id) {
            this.$confirms(() => {
                this.$Api.specsdelete({ id }).then((res) => {
                    console.log(res, 111111);
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                        this.getspecstotal()
                        this.getspecslist({size:1,page:this.specstotal-1})
                    } else {
                        this.$message.error(res.msg)
                    }
                })
            })
            console.log(id, "删除");
        },
        // 修改页面
        changepage(page) {
            this.getspecslist({ size: this.size, page });
        }
    },
    data() {
        return {
            size: 1,
            page: 1,
            info: {
                isShow: false
            }
        }
    },
    components: { vDialog }
}

</script>


<style leng='less' scoped>

</style>